object ScalaString {

  def main(args: Array[String]): Unit = {
    val tenantId = 102503
    val id = 1
    val updatelevelsql =
      s"""update
         |	dim.dim_xl_org
         |set
         |	level_name = a.level_name
         |from
         |	(
         |	select
         |		t.tenant_id,
         |		t.org_nid,
         |		t.level,
         |		case
         |			when strpos(string_agg(t.org_name, '/'), '/')= 0 then string_agg(t.org_name, '/')
         |			else substring(string_agg(t.org_name, '/'), strpos(string_agg(t.org_name, '/'), '/')+ 1)
         |		end level_name
         |	from
         |		(
         |		select
         |			t.tenant_id,
         |			a.org_id org_nid,
         |			a.level,
         |			t.org_id,
         |			t.org_name
         |		from
         |			dim.dim_xl_org t
         |		join dim.dim_xl_org a on
         |			t.tenant_id = a.tenant_id
         |			and string_to_array(a."level" , '/')@> array[cast(t.org_id as text)]
         |			and string_to_array(a."level" , '/')@> array[cast(${id} as text)]
         |		where
         |			1 = 1
         |			and t.tenant_id=${tenantId}
         |		order by
         |			t.tenant_id,
         |			a.org_id ,
         |			t.level_num) t
         |	group by
         |		t.tenant_id,
         |		t.org_nid,
         |		t.level) a
         |where
         |	dim.dim_xl_org.tenant_id = a.tenant_id
         |	and dim.dim_xl_org.org_id = a.org_nid""".stripMargin

    print(updatelevelsql)
  }

}
